package cn.controller;

import cn.pojo.Dev_user;
import cn.tools.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.mapper.dev_user.Dev_userMapper;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RequestMapping("/dev")
@Controller
public class Dev_userController {

    @Resource
    private Dev_userMapper dev_userMapper;

    @RequestMapping("/from")
    public String fromlogin(HttpServletRequest request){
        request.setAttribute("who","dev");
        return "forward:/login.jsp";
    }

    //登录
    @PostMapping("/login")
    public String dev_userLogin(String devCode, String devPassword, HttpServletRequest request){
        Dev_user user=dev_userMapper.getLoginDev_user(devCode,devPassword);
        if (user!=null){
            //放入session
            request.getSession().setAttribute(Constants.DEV_SESSION,user);
            System.out.println( ((Dev_user)request.getSession().getAttribute(Constants.DEV_SESSION)).getId());
            request.getSession().setAttribute("dev",((Dev_user)request.getSession().getAttribute(Constants.DEV_SESSION)).getDevCode());
            return "dev_list";
        }else {
            request.setAttribute("msg","账号名或密码错误!");
            return "forward:/dev/from";
        }
    }

    //进入App维护页面
    @RequestMapping("/devlist")
    public  String devlist(){
        return "dev_from";
    }






}
